﻿(function ($) {
	var defaultOptions = {
		newBook: 'a[data-hash="new"]',
		form: '#new-book'
	};

	function init(options) {

			var opt = $.extend({}, defaultOptions, options);
			$(opt.newBook).click(function (e) {
				e.preventDefault();

				var $form = $('#new-book').clone(true).removeAttr('id').show();
				$form.smarlyValidation({
					createBookUrl: $form.attr('action'),
					onSuccess: function () {
						window.location.href = window.location.href;
						//window.location.reload(true);
					}
				});

				$.SmarlyModal.show({
					header: 'Создание новой книги',
					body: $form,
					closeOnApply: false,
					applyFunc: function () {
						$form.submit();
					}
				});
			});
	}

	$.extend({
		SmarlyAdminMain: init,
	});
})(jQuery);